package agh.tk.markuptranslation;

public class Headline extends AbstractLeaf
{
	private int sectionLevel ;
	private boolean isOrdered = false;
	public Headline(String value, int sectionLevel) 
	{
		super(value);
		this.sectionLevel = sectionLevel ;
		
	}

	/*
	 * doku wiki nie dostarcza opcji uporzadkowanych tytulow 
	 * 
	*/
	@Override
	public String toDokuWiki() 
	{
		StringBuilder stringBuilder = new StringBuilder() ;
		for(int i = 7 ; i > sectionLevel ; i--)
			stringBuilder.append("=") ;
		stringBuilder.append(value) ;
		for(int i = 7 ; i > sectionLevel ; i--)
			stringBuilder.append("=") ;
		return stringBuilder.toString() ;
	}

	//MediaWiki rowniez
	@Override
	public String toMediaWiki() {
		StringBuilder stringBuilder = new StringBuilder() ;
		for(int i = 0 ; i < sectionLevel+1 ; i++) //=cos= to tytul strony
			stringBuilder.append("=") ;
		stringBuilder.append(value) ;
		for(int i = 0 ; i < sectionLevel+1 ; i++)
			stringBuilder.append("=") ;
		return stringBuilder.toString() ;
	}
	
	//HTML jw
	@Override
	public String toHTML() {
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append("<h");
		stringBuilder.append(sectionLevel>6?6:sectionLevel);//Albo "operacja..."
		stringBuilder.append(">");
		stringBuilder.append(value);
		stringBuilder.append("</h");
		stringBuilder.append(sectionLevel>6?6:sectionLevel);
		stringBuilder.append(">");
		return stringBuilder.toString() ;
	}

	@Override
	public String toTxt2tags() 
	{
		char symbol ;
		if(isOrdered)
			symbol = '+' ;
		else
			symbol = '=' ;
		StringBuilder stringBuilder = new StringBuilder() ;
		for(int i = 0 ; i < sectionLevel ; i++)
			stringBuilder.append(symbol) ;
		stringBuilder.append(value) ;
		for(int i = 0 ; i < sectionLevel ; i++)
			stringBuilder.append(symbol) ;
		return stringBuilder.toString() ;
	}
	
	public void setOrdered()
	{
		this.isOrdered = true ;
	}
}
